<template>
  <div>
    <teleport to='body'>
      <!-- 蒙版-->
      <transition name='fade'>
        <!-- @click='emits("update:modelValue",false)'-->
        <div
          v-if='isVisible'
          @click='isVisible = false'
          class='w-screen h-screen bg-zinc-900/80 z-40 fixed top-0 left-0'></div>
      </transition>
      <!-- 内容-->
      <transition name='popup-down-up'>
        <div
          v-if='isVisible'
          v-bind='$attrs' class='w-screen bg-white duration-500 dark:bg-zinc-800 z-50 fixed bottom-0'
        >
          <slot/>
        </div>
      </transition>
    </teleport>
  </div>
</template>

<script setup>
import { useScrollLock,useVModel } from '@vueuse/core'
import { watch } from 'vue'

const props = defineProps({
  modelValue: {
    required:true,
    type:Boolean
  }
})

defineEmits(['update:modelValue'])

// 是一个响应式数据，当 isVisible 值发生变化时，会自动触发 emit 修改 modelValue
const isVisible = useVModel(props)

const isLocked = useScrollLock(document.body)
watch(
  isVisible,
  (val) => {
    isLocked.value = val
  },
  {
    immediate:true
  }
)
</script>

<style lang='scss' scoped>
.fade-enter-active, .fade-leave-active {
  transition: all 0.3s;
}
.fade-enter-from,.fade-leave-to {
  opacity: 0;
}
.popup-down-up-enter-active,
.popup-down-up-leave-active {
  transition: all 0.3s;
}
.popup-down-up-enter-from,
.popup-down-up-leave-to {
  transform: translateY(100%);
}

</style>
